<?php
/**
 * 扩展CI_Controller类
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Controller extends CI_Controller {

	
	/**
	 * Class constructor
	 *
	 * @return	void
	 */
	public function __construct()
	{
		parent::__construct();
	}
	
	
	/**
	* 判断用户是否登录后台
	*/
	public function check_manage_session(){
		if (!$this->session->userdata('logged_in')){          		
			redirect($this->config->item('system_manage_path').'login');
			exit();
		}
	}
	
	
	/**
	* @name 错误跳转公共方法
	* @param string $message 错误提示信息
	* @param number $time 跳转时间 
	* @param string $url 跳转的URL
	*/
	 
	public function error($message,$time = 3,$url = FALSE)
	{
		if( !$url ) {
			$data['url'] = 'javascript:history.back(-1);';
		} else {
			$data['url'] = site_url($url);
		}
		$data['message'] = $message;
		$data['time'] = $time;
		die($this->load->view($this->config->item('system_manage_path').'public/error',$data,true));
	}
	
	/**
	* @name 成功跳转公共方法
	* @param string $message 成功提示信息
	* @param number $time 跳转时间 
	* @param string $url 跳转的URL
	*/
	public function success($message,$time = 3,$url = FALSE)
	{
		if( !$url ) {
			$data['url'] = 'javascript:history.back(-1);';
		} else {
			$data['url'] = site_url($url);
		}
		$data['message'] = $message;
		$data['time'] = $time;
		die($this->load->view($this->config->item('system_manage_path').'public/success',$data,true));
	}
	
	/**
	*@name 自定义分页
	*@param string $model 所属板块
	*@param string $table 要查询的表
	*@param number $page 每页显示记录数
	*@param number $links 当前页左右显示页数
	*/
	public function mypage($model,$table,$page=10,$links=3){
		$config['base_url'] = site_url($this->config->item('system_manage_path').$model.'/page');
		$config['total_rows'] = $this->db->count_all_results($table);//分页的数据总行数
		$config['per_page'] = $page; //每页显示数
		$config['num_links'] = $links;//当前页两边显示数字页数
		$config['use_page_numbers'] = TRUE;
		$config['first_link'] = '首页';
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['last_link'] = '末页';
		$config['last_tag_open'] = '<li>';
		$config['last_tag_close'] = '</li>';
		$config['next_link'] = '下一页';
		$config['next_tag_open'] = '<li>';
		$config['next_tag_close'] = '</li>';
		$config['prev_link'] = '上一页';
		$config['prev_tag_open'] = '<li>';
		$config['prev_tag_close'] = '</li>';
		$config['cur_tag_open'] = '<li class="active"><a>';
		$config['cur_tag_close'] = '</a></li>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$this->pagination->initialize($config); 
		//获取列表数据
		$pagesize=$config['per_page'];
		if ($config['use_page_numbers']) {
			$offset=$config['per_page']*($this->uri->segment(4)-1);
			if ($offset<0){
				$offset=0;
			}
		}else{
			$offset=$this->uri->segment(4);
		}
		return array('pagesize'=>$pagesize,'offset'=>$offset);
	}
	
	
	
}
// END Controller class

/* End of file MY_Controller.php */
/* Location: ./application/core/Controller.php */